﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using DIST.LR.ZHJG.DataModel;
using DIST.LR.ZHJG.WCFServices.EntityDataManageService;
using System.Collections.Generic;

namespace DIST.LR.ZHJG.Pgybc
{
    public class Zbgl_KPIVALUEModel : INotifyPropertyChanged
    {
        protected EntityDataManageServiceClient client = DIST.LR.ZHJG.WCFServices.CommonServices.WCFService;

        public Zbgl_KPIVALUEModel()
        {
            GetKPIValueSource();
        }

        public void GetKPIValueSource()
        {
            string strSql = string.Format("from TKPIVALUE order by ID asc");
            client.SelectTkpiValueCompleted += new EventHandler<SelectTkpiValueCompletedEventArgs>(client_SelectTkpiValueCompleted);
            client.SelectTkpiValueAsync(strSql, "0");
        }


        void client_SelectTkpiValueCompleted(object sender, SelectTkpiValueCompletedEventArgs e)
        {
            int count = Convert.ToInt32(e.Result.Count);
            if (count == 1) return;

            IList<TKPIVALUE> lst = e.Result as IList<TKPIVALUE>;
            ObservableCollection<KPIValue> _kpiValueInfo = new ObservableCollection<KPIValue>();
            KPIValue kpiValue;
            foreach (TKPIVALUE item in lst)
            {
                kpiValue = new KPIValue();
                kpiValue.KPIVALUEEndTime = item.CREATETIME;
                kpiValue.KPIVALUEId = item.ID;
                kpiValue.KPIVALUEKpiId = item.KPIID;
                kpiValue.KPIVALUEStartTime = item.STARTTIME;
                kpiValue.KPIVALUEValue = item.VALUE;
                kpiValue.KPIVALUEValueOrigin = item.VALUEORIGIN;
                kpiValue.KPIVALUEDataTimeType = item.DATETIMETYPE;
                kpiValue.KPIVALUECreateTiem = item.CREATETIME;
                kpiValue.KPIVALUEName = item.NAME;
                _kpiValueInfo.Add(kpiValue);
            }
            KpiValueInfo = _kpiValueInfo;
        }


        private ObservableCollection<KPIValue> kpiValueInfo;
        public ObservableCollection<KPIValue> KpiValueInfo
        {
            get { return this.kpiValueInfo; }
            set
            {
                if (this.kpiValueInfo != value)
                {
                    this.kpiValueInfo = value;
                    this.OnPropertyChanged("KpiValueInfo");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
